﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ProduceBasicData.Api.Application.Command.Material.BOM;
using ProduceBasicData.Api.DTO;
using ProduceBasicData.ErrorCode;

namespace ProduceBasicData.Api.Controllers.Material
{
    /// <summary>
    /// BOM控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BOMController : ControllerBase
    {
        private readonly IMediator mediator;

        public BOMController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// BOM查询接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiPaging<BOMDTO>> GetBom([FromQuery]SerachBOMCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 获取BOM树形结构接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<BOMTreeDTO>>> GetBOMTree([FromQuery]GetBOMTreeCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 删除BOM接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DeleteBom(DeleteBOMCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// BOM新增接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> CreateBOM(CreateBOMCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// BOM修改接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> UpdateBom(UpdateBOMCommand request)
        {
            return await mediator.Send(request);
        }
    }
}
